'''使用turtle库绘制一朵玫瑰花。'''
import turtle as t
import math

def RGB2rgb(R,G,B):
    r,g,b = R/255,G/255,B/255
    colorTp = (r,g,b)
    return colorTp

k=1

#茎干
def stem():
    t.penup()
    t.goto(0,-207*k)
    t.pensize(14)
    t.pencolor(RGB2rgb(16,124,16))
    t.setheading(90)
    t.pendown()
    t.forward(222*k)
    t.penup()

#右侧叶子
def ringhtleaf():
    t.penup()
    x,y = 0,-119.1 
    t.goto(x*k,y*k)
    t.pensize(7)
    t.pencolor(RGB2rgb(16,124,16))
    t.pendown()
    t.fillcolor('#13A10E')
    t.begin_fill()
    while x <= 110.82*k:
        y = (9*(10**(-5)))*(x**3) - 0.0225*(x**2) + 1.7849*x - 119.1
        x += 0.2
        t.goto(x*k,y*k)
    while x>= 0:
        y = (-8*(10**(-5)))*(x**3) + 0.0279*(x**2) - 1.7127*x - 119.1
        x -= 0.2
        t.goto(x*k,y*k)
    t.end_fill()

#左侧叶子
def leftleaf():
    t.penup()
    x,y = 0,-104.1 
    t.goto(x*k,y*k)
    t.pensize(7)
    t.pencolor(RGB2rgb(16,124,16))
    t.pendown()
    t.fillcolor('#13A10E')
    t.begin_fill()
    while x >= -110.37*k:
        y = -0.0094*(x**2) - 1.5238*x - 104.1
        x -= 0.2
        t.goto(x*k,y*k)
    while x<= 0:
        y = 0.0124*(x**2) + 0.8823*x - 104.1
        x += 0.2
        t.goto(x*k,y*k)
    t.end_fill()

#右侧花瓣
def rightpetal():
    t.penup()
    x,y = -28.9093,26.6737
    t.goto(x*k,y*k)
    t.pensize(7)
    t.pencolor(RGB2rgb(239,100,120))
    t.pendown()
    t.fillcolor('#F03A17')
    t.begin_fill()
    #底部
    while x <= 42.5546*k:
        y = 0.0066*(x**2) - 0.2633*x + 13.546
        x += 0.2
        t.goto(x*k,y*k)
    x -= 0.2
    #右侧
    while y<= 215.6755:
        '''x = (-2*(10**(-7)))*(y*4) + 0.0001*(y**3) - \
            0.0347*(y**2) + 3.174*y + 2.7689'''
        x = (5*(10**(-5)))*(y**3) - 0.0219*(y**2) + \
            2.4729*y + 11.49
        y += 0.2
        t.goto(x*k,y*k)
    #左侧
    while y >= 26.6737:
        x = (2*(10**(-7)))*(y**4) -0.0001*(y**3) + \
            0.0228*(y**2) - 2.2134*y +15.705
        y -= 0.2
        t.goto(x*k,y*k)
    t.end_fill()
    
#左侧花瓣
def lefttpetal():
    t.penup()
    x,y = 0,186.6
    t.goto(x*k,y*k)
    t.pensize(7)
    t.pencolor(RGB2rgb(239,100,120))
    t.pendown()
    t.fillcolor('#F03A17')
    t.begin_fill()
    #右侧
    while x >= -41.7952:
        y = -0.00247*(x**2) - 0.7029*x + 186.54
        t.goto(x*k,y*k)
        x -= 0.2
    #左侧
    while y >= 25.5052:
        x = (-4*(10**(-5)))*(y**3) + 0.0182*(y**2) - \
            2.1649*y - 19.628
        t.goto(x*k,y*k)
        y -= 0.2
    print(x,y)
    while y >= 7.05:
        x = (6*(10**(-6)))*(y**4) - 0.00174*(y**3) + \
            0.1729*(y**2) - 7.9227*y +53
        t.goto(x*k,y*k)
        y -= 0.2
    t.end_fill()

#上花瓣
def topprtal():
    t.penup()
    x,y = 51.4,217.3
    x1,y1 = x - 20,y - 40
    t.goto(x1*k,y1*k)
    t.pensize(7)
    t.pencolor(RGB2rgb(239,100,120))
    t.pendown()
    t.fillcolor('#F03A17')
    t.begin_fill()
    #右侧
    x,y = 19.0,249.5
    x1,y1 = x - 20,y - 40
    t.goto(x1*k,y1*k)
    #左侧
    while x >= -20.7952:
        y = -0.0032*(x**2) + 0.3065*x +244.85
        x1,y1 = x - 20,y - 40
        t.goto(x1*k,y1*k)
        x -= 0.2
    t.goto(0,50)
    x,y = 51.4,217.3
    x1,y1 = x - 20,y - 40
    t.goto(x1*k,y1*k)
    t.end_fill()
#花蒂
def base():
    t.penup()
    x,y = -70.9,39.5
    t.goto(x,y)
    t.pencolor(RGB2rgb(16,124,16))
    t.fillcolor('#13A10E')
    t.pendown()
    t.begin_fill()
    while x <= 70.9:
        y = (10**(-6))*(x**4) + (7*(10**(-17)))*(x**3) + \
               0.0015*(x**2) - (10**(-12))*x + 4.5
        t.goto(x*k,y*k)
        x += 0.2
    t.goto(18.3,28.5)
    t.goto(0,60)
    t.goto(-18.3,28.5)
    t.goto(-70.9,39.5)
    t.end_fill()
               
stem()
ringhtleaf()
leftleaf()
topprtal()
lefttpetal()
rightpetal()
base()
t.hideturtle()
